const { merge } = require('webpack-merge')
const tsImportPluginFactory = require('ts-import-plugin')

module.exports = {
  devServer: {
    open: true,
    proxy: {
      '/api': {
        target: 'https://music-serve-two.vercel.app/',
        changeOrigin: true,
        pathRewrite: {
          '/api': '/',
        },
      },
    },
  },
  chainWebpack: (config) => {
    config.module
      .rule('ts')
      .use('ts-loader')
      .tap((options) => {
        options = merge(options, {
          transpileOnly: true,
          getCustomTransformers: () => ({
            before: [
              tsImportPluginFactory({
                libraryName: 'vant',
                libraryDirectory: 'es',
                style: true,
              }),
            ],
          }),
          compilerOptions: {
            module: 'es2015',
          },
        })
        return options
      })
  },
}
